package com.hqd.ch03.v20.utils;

import com.hqd.ch03.v20.aop.framework.aspectj.AspectJAdviceParameterNameDiscoverer;
import org.apache.commons.lang3.StringUtils;

public abstract class AspectJProxyUtils {
    public static boolean isJoinPointRelatedParam(String name) {
        return isJoinPointParam(name) || isStaticPartParam(name);
    }

    public static boolean isJoinPointParam(String name) {
        return StringUtils.equalsAny(name, AspectJAdviceParameterNameDiscoverer.THIS_JOIN_POINT);
    }

    public static boolean isStaticPartParam(String name) {
        return StringUtils.equals(name,
                AspectJAdviceParameterNameDiscoverer.THIS_JOIN_POINT_STATIC_PART);
    }

    public static boolean isVariableName(String name) {
        if (StringUtils.isBlank(name)) {
            return false;
        }
        if (!Character.isJavaIdentifierStart(name.charAt(0))) {
            return false;
        }
        for (int i = 1; i < name.length(); i++) {
            if (!Character.isJavaIdentifierPart(name.charAt(i))) {
                return false;
            }
        }
        return true;
    }
}
